import axios from 'axios'

// 导出Excel公用方法
export function exportMethod(data) {
    axios({
        method: data.method,
        url:process.env.API_ROOT+data.url,
        data:data.data,
        responseType: 'blob'
    }).then((res) => {
        console.log(res,"7777777");
        const link = document.createElement('a')
        let blob = new Blob([res.data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob)
 
        // link.download = res.headers['content-disposition'] //下载后文件名
        let time=new Date().getTime()
        link.download = "导出表格-"+time
        // link.download = decodeURI(res.headers['content-disposition']).split('=')[1] //下载的文件名
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
        alert("导出成功")
        // this.$Message.success('This is a success tip');
    })
    // .catch(error => {
    //     this.$Notice.error({
    //         title: '错误',
    //         desc: '网络连接错误'
    //     })
    //     // console.log(error)
    // })
}